﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tosi
{
    class DataFile
    {
        private string ftext;
        private string fContent;
        private string[] fString;
        public DataFile()
        {
            ftext = "../../TextFile1.txt";
        }
        public void Read(out int n, out double[,] vekt1, out string[] vekt2,
            out int m, out int[,] vekt3, out string[] vekt4)
        {
            fContent = File.ReadAllText(ftext);
            fString = fContent.Split(new char[] { ' ', '\r', '\n', '\t' },
                StringSplitOptions.RemoveEmptyEntries);
            n = int.Parse(fString[0]);
            vekt1 = new double[n, 2];
            vekt2 = new string[n];
            int offset = 1;
            for (int i = 0; i < n; i++)
            {
                vekt1[i, 0] = double.Parse(fString[offset++]);
                vekt1[i, 1] = double.Parse(fString[offset++]);
                vekt2[i] = fString[offset++];
            }
            m = int.Parse(fString[offset++]);
            vekt3 = new int[m, 3];
            vekt4 = new string[m];
            for (int i = 0; i < m; i++)
            {
                vekt3[i, 0] = int.Parse(fString[offset++]);
                vekt3[i, 1] = int.Parse(fString[offset++]);
                vekt3[i, 2] = int.Parse(fString[offset++]);
                vekt4[i] = fString[offset++];
            }
        }
        public void Write(int n, double[,] vekt1, string[] vekt2, int m, int[,] vekt3, string[] vekt4)
        {
            fContent = "";
            fContent += n; fContent += "\r\n";
            for (int i = 0; i < n; i++)
            {
                fContent += vekt1[i, 0];
                fContent += "\t";
                fContent += vekt1[i, 1];
                fContent += "\t";
                fContent += vekt2[i];
                fContent += "\r\n";
            }
            fContent += "\r\n";
            fContent += m; fContent += "\r\n";
            for (int i = 0; i < m; i++)
            {
                fContent += vekt3[i, 0];
                fContent += '\t';
                fContent += vekt3[i, 1];
                fContent += '\t';
                fContent += vekt3[i, 2];
                fContent += '\t';
                fContent += vekt4[i];
                fContent += "\r\n";
            }
            fContent += "\r\n";
            File.WriteAllText(ftext, fContent);
        }
    }   
}
